package com.ruoyi.project.data.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.data.mapper.WeightEquipmentMapper;
import com.ruoyi.project.data.domain.WeightEquipment;
import com.ruoyi.project.data.service.IWeightEquipmentService;

/**
 * 设备信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-21
 */
@Service
public class WeightEquipmentServiceImpl implements IWeightEquipmentService 
{
    @Autowired
    private WeightEquipmentMapper weightEquipmentMapper;

    /**
     * 查询设备信息
     * 
     * @param id 设备信息ID
     * @return 设备信息
     */
    @Override
    public WeightEquipment selectWeightEquipmentById(Long id)
    {
        return weightEquipmentMapper.selectWeightEquipmentById(id);
    }

    /**
     * 查询设备信息列表
     * 
     * @param weightEquipment 设备信息
     * @return 设备信息
     */
    @Override
    public List<WeightEquipment> selectWeightEquipmentList(WeightEquipment weightEquipment)
    {
        return weightEquipmentMapper.selectWeightEquipmentList(weightEquipment);
    }

    /**
     * 新增设备信息
     * 
     * @param weightEquipment 设备信息
     * @return 结果
     */
    @Override
    public int insertWeightEquipment(WeightEquipment weightEquipment)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        weightEquipment.setCreateId(user.getUserId().toString());
        weightEquipment.setCreateTime(DateUtils.getNowDate());
        return weightEquipmentMapper.insertWeightEquipment(weightEquipment);
    }

    /**
     * 修改设备信息
     * 
     * @param weightEquipment 设备信息
     * @return 结果
     */
    @Override
    public int updateWeightEquipment(WeightEquipment weightEquipment)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        weightEquipment.setUpdateId(user.getUserId().toString());
        weightEquipment.setUpdateTime(DateUtils.getNowDate());
        return weightEquipmentMapper.updateWeightEquipment(weightEquipment);
    }

    /**
     * 批量删除设备信息
     * 
     * @param ids 需要删除的设备信息ID
     * @return 结果
     */
    @Override
    public int deleteWeightEquipmentByIds(Long[] ids)
    {
        return weightEquipmentMapper.deleteWeightEquipmentByIds(ids);
    }

    /**
     * 删除设备信息信息
     * 
     * @param id 设备信息ID
     * @return 结果
     */
    @Override
    public int deleteWeightEquipmentById(Long id)
    {
        return weightEquipmentMapper.deleteWeightEquipmentById(id);
    }

    @Override
    public String checkEquipmentCodeUnique(WeightEquipment weightEquipment) {
        int count = weightEquipmentMapper.checkEquipmentCodeUnique(weightEquipment);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
